/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Other;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import javax.mail.Multipart;
import javax.mail.Part;

/**
 *
 * @author Envy
 */
public class Attachment {

    private String keyPath = "";
    private javax.swing.JFileChooser key_choose1;
    Multipart m;

    public void Attachment() {
        try {
            // TODO add your handling code here:
            keyPath = this.key_choose1.getSelectedFile().getPath();
            Part content_text = m.getBodyPart(1);
            String disposition = content_text.getDisposition();
            byte[] s;
            if (disposition.equals("ATTACHMENT")) {
                InputStream inf = content_text.getInputStream();
                ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                int nRead;
                byte[] data = new byte[10000];
                while ((nRead = inf.read(data, 0, data.length)) != -1) {
                    buffer.write(data, 0, nRead);
                }
                buffer.flush();
                s = buffer.toByteArray();
                DecryptSymmetric d = new DecryptSymmetric();
                byte[] results = d.DecryptSymmetric(s, keyPath);
                String result = new String(results);
                System.out.println("After decrypt: " + result);

            } else {
                //not handle
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
        }
    }
}
